#include <stdio.h>
#include <string>

using std::string;

string multiply(string num1, string num2) {
    if (num1 == "" || num2 == "") {
        return "";
    }
    if (num1 == "0" or num2 == "0") {
        return "0";
    }
    int l1 = num1.size(), l2 = num2.size();
    // 89 * 76
    string result(l1+l2, '0'); // 0000
    for (int i = l1-1; i >= 0; --i) {
        int add = 0;
        for (int j = l2-1; j >= 0; --j) {
            int mul = (num1[i]-'0') * (num2[j]-'0'); // 9*6 = 54; 9*7 = 63; 48
            int sum = mul%10 + add + result[i+j+1]-'0'; // 4+0+0; 3+5+0;
            result[i+j+1] = sum%10 + '0'; // 0004; 0084
            add = mul/10 + sum/10; // 5+0; 6+0
        }
        result[i] += add; // 0684
    }
    // incase 0 is at the front of result
    for (int i = 0; i < l1+l2; ++i) {
        if (result[i] != '0') {
            return result.substr(i);
        }
    }
    return "0";
}

int main() {
    printf("%s\n", multiply("89", "97").c_str());
    return 0;
}
